package seekting.demo2017.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.seekting.demo_lib.Demo;

/**
 * Created by Administrator on 2017/8/26.
 */
@Demo(title = "ThreadLocalActivity", desc = "")
public class ThreadLocalActivity extends Activity {
    public static ThreadLocal<User> threadLocal = new ThreadLocal<>();


    private static class User {
        String name = "";
        int age;

        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        User user = new User("seekting", 31);
        threadLocal.set(user);
        user = new User("seekting1", 32);
        threadLocal.set(user);

        User u = threadLocal.get();
        Log.d("seekting", "ThreadLocalActivity.onCreate()" + u);
        Log.d("seekting", "ThreadLocalActivity.onCreate()" + u);
        Thread thread = new Thread() {
            @Override
            public void run() {
                super.run();
//                threadLocal.get();
                Log.d("seekting", "thread.run()" + threadLocal.get());
            }
        };
        thread.start();

    }
}
